package Thread;

class Res{
    public int res = 0;
    public Object lock = new Object();
}

public class Demo4 {
    public static void main(String[] args) throws InterruptedException {
        Res res = new Res();
        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                int sum = 0;
                for (int i = 1; i <= 1000; i++) {
                    sum+=i;
                }
                synchronized (res.lock) {
                    res.res = sum;
                    res.lock.notify();
                }
            }
        });
        t.start();
        while(res.res==0){
            synchronized (res.lock){
                res.lock.wait();
                if (res.res != 0) {
                    System.out.println(res.res);
                }
            }
        }
    }

}